fix: return TaskNotFoundError when SendMessage references non-existent taskId#788
fix: return TaskNotFoundError when SendMessage references non-existent taskId#788yyy9942 wants to merge 1 commit intoa2aproject:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request enforces A2A spec section 3.4.2 by prohibiting client-provided taskId values for new task creation. The DefaultRequestHandler now validates that any provided taskId references an existing task, throwing a TaskNotFoundError otherwise. It also ensures that follow-up messages maintain the original contextId of a task. Correspondingly, integration and unit tests across multiple modules have been updated to rely on server-generated IDs and content-based routing for test scenarios. I have no feedback to provide.
|
This may have introduced, or at least exposed, a transport-specific regression in the new test path. In GitHub Actions run 24245000423 on April 13, 2026, the failing test is: Failure: What makes this look PR-related:
Minimal reproduction candidate: mvn -pl reference/jsonrpc -am \
-Dtest=QuarkusA2AJSONRPCVertxTest#testAgentToAgentLocalHandling \
-Dsurefire.failIfNoSpecifiedTests=false \
testThe later MultiInstanceReplicationTest failure looks secondary:
I haven't reproduced it locally yet, but the CI failure looks pretty tightly aligned with the test-path changes in this PR. |
| // Per A2A spec section 3.4.2: when a client includes a taskId in a | ||
| // Message, it MUST reference an existing task. Client-provided taskId | ||
| // for creating new tasks is not supported. | ||
| if (task == null && params.message().taskId() != null) { |
There was a problem hiding this comment.
I find this check a bit convoluted.
It can be simplified by verifying at the start of the method that if params.message().taskId() is not null, there is a task returned by taskStore.get(params.message().taskId()).
After that, the request context can be safely created from either a correct message's taskId or an autogenerated taskId.
There was a problem hiding this comment.
@jmesnil Simplified the check as suggested. Extracted the taskId validation into validateRequestedTask() at the top of the method - if params.message().taskId() is non-null, it verifies the task exists, validates contextId consistency, and rejects terminal-state tasks upfront. After that, initMessageSend() can safely work with either a validated existing task or proceed with auto-generated identifiers for new tasks.
Also pulled out normalizeRequestParamsForTask() to align message params with the task's canonical IDs before building the RequestContext, and merged the two consecutive if (task != null) blocks into one.
da31489 to
668792f
Compare
…t taskId Per A2A spec section 3.4.2, when a client includes a taskId in a Message, it MUST reference an existing task. Previously, the SDK silently created a new task using the client-provided taskId, which the spec explicitly forbids. Applies to all three transports (JSON-RPC, gRPC, HTTP+JSON) via the common DefaultRequestHandler.initMessageSend() code path. Existing tests that relied on the buggy behaviour have been updated to either pre-populate the task store (when testing follow-up messages) or omit the client-provided taskId on the initial message (letting the server generate it, matching the spec-correct flow). This fixes a2aproject#766
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors task creation and message handling to strictly enforce server-side task ID generation, aligning with the A2A specification (CORE-MULTI-004). Key changes include the introduction of task validation in DefaultRequestHandler to reject client-provided IDs for new tasks and the update of various integration tests to handle server-generated IDs. I have no feedback to provide.
Per A2A spec section 3.4.2, when a client includes a taskId in a Message, it MUST reference an existing task. The SDK was creating a new task with that id instead.
Added a guard in DefaultRequestHandler.initMessageSend() that throws TaskNotFoundError when the provided taskId does not reference an existing task.
This fixes the issue on all three transports (JSON-RPC, gRPC, HTTP+JSON) since they all use the same DefaultRequestHandler code path.
Also fixes a related contextId bug: when a follow-up message had a taskId but no contextId, RequestContext.Builder.build() was generating a fresh UUID, so the agent executor saw the wrong contextId. The rebuild now seeds contextId from the stored task.
Existing tests that relied on the old taskId behavior have been updated.
Fixes #766